package com.lc.hongtai.activity;

import android.content.Context;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.lc.hongtai.R;
import com.lc.hongtai.conn.JsonAccessToken;
import com.lc.hongtai.conn.JsonSectuty;
import com.zcx.helper.bound.BoundView;
import com.zcx.helper.http.AsyCallBack;

/**
 * Created by Administrator on 2017/4/20.
 */

public class SecurityActivity extends BaseActivity implements ImageView.OnClickListener {

    private ImageView iv_back;
    @BoundView(R.id.convenientBanner)
    ConvenientBanner convenientBanner;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_security);
        iv_back = (ImageView) findViewById(R.id.iv_back);
        iv_back.setOnClickListener(this);

        getTypeAccessToken();
    }

    private void getTypeAccessToken() {
        new JsonAccessToken("index/aqbz", new AsyCallBack<JsonAccessToken.Info>() {
            @Override
            public void onSuccess(String toast, int type, JsonAccessToken.Info info) throws Exception {
                super.onSuccess(toast, type, info);
                initData(info.access_token);
            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }).execute(this, false);
    }

    private void initData(String access_token) {
        new JsonSectuty(new AsyCallBack<JsonSectuty.Info>() {

            @Override
            public void onStart(int type) throws Exception {
                super.onStart(type);

            }

            @Override
            public void onSuccess(String toast, int type, JsonSectuty.Info info) throws Exception {

            /*    convenientBanner.setPages(
                        new CBViewHolderCreator<SecurityActivity.LocalImageHolderView>() {
                            @Override
                            public SecurityActivity.LocalImageHolderView createHolder() {
                                return new SecurityActivity.LocalImageHolderView();
                            }
                        }, info.).setPageIndicator(new int[]{R.mipmap.ic_dots_uncheck, R.mipmap.ic_dots_check})
                        //设置指示器的方向
                        .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL).setCanLoop(true);*/

                convenientBanner.setPages(
                        new CBViewHolderCreator<SecurityActivity.LocalImageHolderView>() {
                            @Override
                            public SecurityActivity.LocalImageHolderView createHolder() {
                                return new SecurityActivity.LocalImageHolderView();
                            }
                        }, info.banner).setPointViewVisible(false)
                        //设置指示器的方向
                        .setPageIndicatorAlign(ConvenientBanner.PageIndicatorAlign.CENTER_HORIZONTAL).setCanLoop(true);

            }
        }).execute(SecurityActivity.this, false);
    }


    @Override
    public void onClick(View view) {
        super.onClick(view);
        switch (view.getId()) {
            case R.id.iv_back:
                finish();
                break;
        }
    }


    public class LocalImageHolderView implements Holder<JsonSectuty.Banner> {
        private SimpleDraweeView imageView;

        @Override
        public View createView(Context context) {
            imageView = new SimpleDraweeView(context);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            return imageView;
        }

        @Override
        public void UpdateUI(Context context, int position, JsonSectuty.Banner data) {
            imageView.setImageURI(Uri.parse(data.img));
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                  /*  Intent intent = new Intent();
                    intent.putExtra("title", listContent.title);
                    intent.putExtra("url", listContent.url);

                    intent.setClass(getActivity(), AdvertisingActivity.class);
                    getActivity().startActivity(intent);*/
                }
            });
        }

     /*   @Override
        public void UpdateUI(Context context, final int position, final JsonIndex.Info.BannerListContent listContent) {
            imageView.setImageURI(Uri.parse(listContent.img));
            imageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent = new Intent();
                    intent.putExtra("title", listContent.title);
                    intent.putExtra("url", listContent.url);
                    *//*intent.putExtra("url", listContent.url);

                    Log.d(listContent.url, "88888888888888888888888888");*//*
                    intent.setClass(getActivity(), AdvertisingActivity.class);
                    getActivity().startActivity(intent);
                }
            });
        }*/
    }
}
